part of 'component.dart';

class RedNum extends StatelessWidget {
  const RedNum({
    Key? key,
    this.count,
    this.fontSize,
  }) : super(key: key);
  final int? count;
  final double? fontSize;
  @override
  Widget build(BuildContext context) {
    int redCount = count ?? 0;
    var redStr = '$redCount';
    var fs = fontSize ?? 10.sp;

    if (redCount > 99) {
      redStr = '99+';
    }
    if (redCount > 9) {
      fs -= 2.r;
    }
    var redHeight = fs + 5.r;
    return Visibility(
      visible: redCount > 0,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(redHeight / 2),
        child: Container(
          height: redHeight,
          constraints: BoxConstraints(minWidth: redHeight),
          padding: EdgeInsets.symmetric(horizontal: 3.r),
          alignment: Alignment.center,
          decoration: const BoxDecoration(
            color: Colors.red,
          ),
          child: Text(
            redStr,
            style: TextStyle(color: Colors.white, fontSize: fs),
          ),
        ),
      ),
    );
  }
}

class RedNumContainer extends StatelessWidget {
  const RedNumContainer({
    Key? key,
    required this.child,
    required this.childSize,
    this.redCount = 0,
    this.offx,
    this.height,
    this.fontSize,
  }) : super(key: key);
  final Widget child;
  final double childSize;
  final int redCount;
  final double? offx;
  final double? height;
  final double? fontSize;
  @override
  Widget build(BuildContext context) {
    var h = height ?? childSize;
    var x = offx ?? 4.r;
    var offy = 3.r;
    return SizedBox(
      height: h + offy,
      width: childSize + x * 2,
      child: Stack(
        children: [
          Positioned(
            top: offy,
            right: x,
            child: child,
          ),
          Positioned(
            right: 0,
            child: RedNum(count: redCount),
          )
        ],
      ),
    );
  }
}

class RedDotContainer extends StatelessWidget {
  const RedDotContainer({
    Key? key,
    required this.child,
    this.dotSize = 6,
    this.isRead = false,
  }) : super(key: key);
  final Widget child;
  final double dotSize;
  final bool isRead;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Stack(
          children: [
            Positioned(
              child: Container(
                margin: EdgeInsets.only(top: dotSize / 2, right: dotSize / 2),
                child: child,
              ),
            ),
            Positioned(
              right: 0,
              top: 0,
              child: Container(
                height: dotSize,
                width: dotSize,
                decoration: !isRead
                    ? BoxDecoration(
                        color: Colors.red,
                        borderRadius: BorderRadius.circular(dotSize / 2),
                      )
                    : null,
              ),
            )
          ],
        ),
      ],
    );
  }
}
